package com.ray.springboot_jsp_shiro.shiro.realms;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;

/**
 *
 */
public class CustomerRealm extends AuthorizingRealm {
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
        return null;
    }

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        System.out.println("******realm doGetAuthenticationInfo******");
        String principal = (String) token.getPrincipal();
        // 假设我们在这里查到了zhourui这么个用户, 名称一样我们就把名称和密码都送上去
        if("zhourui".equals(principal)){
            return new SimpleAuthenticationInfo(principal, "123456", this.getName());
        }
        return null;
    }
}
